`strip`ing the results of a split in python

Posted by Igor on Stack Overflow See other posts from Stack Overflow or by Igor
Published on 2010-04-23T00:37:32Z Indexed on 2010/04/23 0:43 UTC
Read the original article Hit count: 316

Filed under:
|

i'm trying to do something pretty simple:

line = "name      :    bob"
k, v = line.lower().split(':')
k = k.strip()
v = v.strip()

is there a way to combine this into one line somehow? i found myself writing this over and over again when making parsers, and sometimes this involves way more than just two variables.

i know i can use regexp, but this is simple enough to not really have to require it...

© Stack Overflow or respective owner

Related posts about python

Related posts about parsing